package com.ruoyi.jpbi.controller.jianshe;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.jianshe.Fomation;
import com.ruoyi.jpbi.domain.jianshe.Plancontrolcost;
import com.ruoyi.jpbi.service.FomationService;
import com.ruoyi.jpbi.service.PlancontrolcostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auto zh
 * date 2019/10/16
 * 计划可控费用
 */
@Controller
@RequestMapping("/jianshe/plancontrolcost")
public class PlancontrolcostController extends BaseController {

    @Autowired
    PlancontrolcostService plancontrolcostService;

    @Autowired
    FomationService fomationService;

    private String prefix = "jpbi/jianshe/plancontrolcost";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user(ModelMap mmap) {
        return prefix + "/plancontrolcost";
    }

    /**
     * 获取计划可控费用数据
     *
     * @param plancontrolcost 条件查询对象
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo getPlancontrolcostList(Plancontrolcost plancontrolcost, ModelMap mmap) {
        startPage();
        List<Plancontrolcost> plancontrolcosts = plancontrolcostService.findAllByUser(plancontrolcost);
        return getDataTable(plancontrolcosts);
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/add";
    }

    /**
     * 新增计划可控费用
     *
     * @param plancontrolcost
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@Validated Plancontrolcost plancontrolcost) {
        return toAjax(plancontrolcostService.insertPlancontrolcost(plancontrolcost));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("controlcost", plancontrolcostService.findAllById(id));
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/edit";
    }
    /**
     * 修改计划产值
     *
     * @param plancontrolcost
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@Validated Plancontrolcost plancontrolcost) {
        return toAjax(plancontrolcostService.updatePlancontrolcost(plancontrolcost));
    }

    /**
     *删除计划产值
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(plancontrolcostService.deletePlancontrolcost(ids));
    }
}
